<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">

							<div class="layui-form-item">
								<label class="layui-form-label">姓名：</label>
								<div class="layui-input-block">
									<input type="text" name="name" placeholder="请输入姓名" autocomplete="off"
										class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">会员名：</label>
								<div class="layui-input-block">
									<input type="text" name="membername" placeholder="请输入姓名" autocomplete="off"
										class="layui-input" readonly="readonly">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">性别：</label>
								<div class="layui-input-block sex"></div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">手机号码：</label>
								<div class="layui-input-block">
									<input type="text" name="mobile" lay-verify="required" placeholder="请输入手机号码"
										autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">层级：</label>
								<div class="layui-input-block">
									<input type="text" name="level" lay-verify="required" placeholder="层级"
										autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">分配权限：</label>
								<div class="layui-input-block">
									<select name="role_id" class="role_id" id="role_id"
										lay-filter="select-schemaList-value"></select>
								</div>
							</div>

						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id'),
			}

			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form;
				sex_show('radio');

				initrole()

				function initrole() {
					$.ajax({
						url: server.querymember_role,
						type: 'post',
						dataType: 'json',
						success: function(data) {
							var data = data.member_role_list.data;
							var html = '<option value="">全部</option>';
							for (var i = 0; i < data.length; i++) {
								html += '<option value=' + data[i].id + '>' + data[i].name + '</option>'
							}
							$(".role_id").append(html);
							form.render('select')
							if (_data.id) {
								initdata();
							}
						},
						'error': function() {
							layer.msg('系统错误');
						}
					})
				}
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					var lock = false
					layer.confirm('确定要提交数据？', function() {
						if (!lock) {
							lock = true
							loading();
							if (_data.id) {
								submitdata(server.member_edit);
							} else {
								delete _data.id;
								submitdata(server.member_insert);
							}
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}

				function initdata() {
					$.get(server.member_detail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.member
								$("#role_id").find("option[value=" + data.data.role_id + "]").attr("selected",
									true);
								form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
			});
		</script>
	</body>

</html>
